$(function(){
	//--显示打卡日历
	showCalendar();
	
	// 载入打卡切换按钮事件
	changecalendar();
	
	
	// 看视频入口
	if(_isAddGold>0){
		var key = $("#_key").val();
		if(_isLogin>0){
			_normalAddGold(key);
		}else{
			_loginToAddGold(key);
		}
	}
	
	$('#normalAddGold').click(function(){
		normalAddGold();
	});
	$('#loginToAddGold').click(function(){
		loginToAddGold();
	});
	
});

function _checkLogin(){
	if(!(_isLogin>0)){
		alert("请先登录！");
		return false;
	}else{
		return true;
	}
}
//显示打卡日历
function showCalendar(){
	var myDate = new Date();
	var m = Number(myDate.getMonth())+Number(1);
	if(m == 7){
		$('#_calendar8').hide();
	}else{
		$('#_calendar7').hide();
	}
}


//打卡
function runCard(){
	if(!_checkLogin()) return false;
	var suburl = _url + "/Card/onRunCard";
	$.getJSON(suburl, function(data){
		if(data.status=1){
			alert(data.msg);
			window.top.location.reload();
		}else{
			alert(data.msg);
		}
	});
}

//打卡日期错误
function runFlaseCard(){
	if(!_checkLogin()) return false;
	var myDate = new Date();
	var y = myDate.getFullYear();
	var m = Number(myDate.getMonth())+Number(1);
	var d = myDate.getDate();
	alert('打卡日期错啦，今天是：'+y+'-'+m+'-'+d);
}

//切换拍卖期数
function changeAuctionPeriods(num){
	var class_name = 'periods_'+num;
	var class_title_name = 'periods_title_'+num;
	
	$("#periods_title_1").css("color","#fff");
	$("#periods_title_2").css("color","#fff");
	$("#periods_title_3").css("color","#fff");
	$("#periods_title_4").css("color","#fff");
	$("#"+class_title_name).css("color","yellow");
	
	$("#periods_1").hide();
	$("#periods_2").hide();
	$("#periods_3").hide();
	$("#periods_4").hide();
	$("#"+class_name).show();
}

// 拍卖出价
function onOffer(_id){
	if(!_checkLogin()) return false;
	var suburl = _url + "/Auction/onOffer/au_id/"+_id;
	$.getJSON(suburl, function(data){
		if(data.status==1){
			alert(data.msg);
			window.top.location.reload();
		}else{
			alert(data.msg);
		}
	});
}


//弹窗获取金币
function _normalAddGold(_key){
	var kspurl=_url+'/Index/ksp/key/' + _key
	 Boxy.load(kspurl, {title:'金币领取',width:450,height:200});
}

function normalAddGold(){
	var key = $("#_key").val();
	var suburl = _url + '/Gold/mediaForGold/key/' + key;
	$.getJSON(suburl, function(data){
		if(data.status==1){
			alert(data.msg);
			window.top.location.href=_url;
		}else{
			alert(data.msg);
		}
	});
}

//登录弹窗获取金币
function _loginToAddGold(_key){
	var kspzcurl=_url+'/Index/kspzc/key/' + _key
	 Boxy.load(kspzcurl, {title:'金币领取',width:450,height:308});
}

function loginToAddGold(){
	var key = $("#_key").val();
	var mobile = $("#u_mobile").val();
	var type = 'u_mobile';
	var pass = $("#u_password").val();
	var suburl = _url + '/Public/onajaxLogin/key/' + key;
	$.post(suburl,{u_mobile:mobile, u_password:pass, type:type }, function(data){
		if(data.status==1){
			alert(data.msg);
			window.top.location.href=_url;
		}else{
			alert(data.msg);
		}
	},'json');
}









